package Java8实战._1_Lambda._4_筛选颜色重量作为参数;

import _17_函数式编程.Lambda.Apple;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class _4_筛选颜色重量作为参数 {

    public static void main(String[] args) {
        List<Apple> inventory = Arrays.asList(
                new Apple("red",150),
                new Apple("green",123),
                new Apple("green",189)
        );

        List<Apple> result;

        result = filter(inventory, "green", 150);
        printAppleList(result);
    }

    public static List<Apple> filter(List<Apple> inventory, String color, int weight){

        List<Apple> list = new ArrayList<>();
        for (Apple apple : inventory){
            if(
                    color.equals(apple.getColor()) &&
                    apple.getWeight() >= 150
            )
                list.add(apple);
        }
        return list;
    }

    public static void printAppleList(List<Apple> list){
        for (Apple apple : list){
            System.out.println("苹果的颜色：" + apple.getColor() + "，苹果的重量：" + apple.getWeight());
        }
    }
}
